<template>
	<div>
		<AplidForm ref="formRef" v-bind="ExtendFormConfig" v-model="formModel" @submit="onSubmit"> </AplidForm>
	</div>
</template>

<script setup lang="ts">
import apiMod from '@/apiMod'
import { ExtendFormConfig } from '../../config'
import { useCommonStore } from '@/stores/common'
import {getAreaObj} from '@/utils/util'

const emit = defineEmits(['refresh'])
const formModel = ref({
	dp_practitioners_experience: [],
	dp_training_record: [],
	dp_subsidy_info: [],
	dp_reward_punishment_info: [],
	dp_foundation_social_title: [],
})
const formRef = ref(null)

const onSubmit = (form, done) => {
	const { tempNowObj } = storeToRefs(useCommonStore())
	// 从业经历
	const dpPractitionersExperiencePOList =
		form.dp_practitioners_experience &&
		form.dp_practitioners_experience.map((item) => {
			return {
				...item,
				idCard: tempNowObj.value.idCard,
				code: 2009,
			}
		})
	// 奖/处罚信息
	const dpRewardPunishmentInfoPOList =
		form.dp_reward_punishment_info &&
		form.dp_reward_punishment_info.map((item) => {
			return {
				...item,
				idCard: tempNowObj.value.idCard,
				code: 2012,
			}
		})
	// 补贴信息
	const dpSubsidyInfoPOList =
		form.dp_subsidy_info &&
		form.dp_subsidy_info.map((item) => {
			return {
				...item,
				idCard: tempNowObj.value.idCard,
				code: 2011,
			}
		})
	// 培训记录
	const dpTrainingRecordPOList =
		form.dp_training_record &&
		form.dp_training_record.map((item) => {
			return {
				...item,
				idCard: tempNowObj.value.idCard,
				code: 2010,
			}
		})
	// 社会职务
	const dpFoundationSocialTitlePOList =
		form.dp_foundation_social_title &&
		form.dp_foundation_social_title.map((item) => {
			return {
				...item,
				idCard: tempNowObj.value.idCard,
				code: 3037,
			}
		})

	const params = {
		...form,
		dpPractitionersExperiencePOList,
		dpRewardPunishmentInfoPOList,
		dpSubsidyInfoPOList,
		dpTrainingRecordPOList,
    dpFoundationSocialTitlePOList,
		idCard: tempNowObj.value.idCard,
		code: 2008,
    dp_practitioners_experience: undefined,
		dp_training_record: undefined,
		dp_subsidy_info: undefined,
		dp_reward_punishment_info: undefined,
		dp_foundation_social_title: undefined,
	}
	apiMod
		.view_dpFoundationPractitionersExtend_gatherAll(params)
		.then((res) => {
			emit('refresh', res.data)
			done()
		})
		.catch((err) => {
			done()
		})
}

const onSave = () => {
	formRef.value!.onSubmit()
}
defineExpose({
	onSave,
})
</script>

<style scoped></style>
